HTMLify
index.html
Views: 374 | Author: cody
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <title>Rollback Toggle</title> <meta name="viewport" content="width=device-width, initial-scale=1" /> <link rel="stylesheet" type="text/css" media="screen" href="style.css" /> </head> <body> <label class="switch"> <input class="switch__input" id="dummy" type="checkbox" role="switch" /> <span class="switch__shadow"> <span class="switch__shadow-inner"></span> </span> <span class="switch__ball-shadow"></span> <span class="switch__ball-shadow-outer"></span> <span class="switch__ball"> <span class="switch__ball-texture"></span> </span> <span class="switch__label">Toggle</span> </label> <script> "use strict"; window.addEventListener("DOMContentLoaded", () => { const rt = new RollbackToggle("#dummy"); }); class RollbackToggle { constructor(el) { var _a; this.restoreTimeout = 0; this.input = document.querySelector(el); (_a = this.input) === null || _a === void 0 ? void 0 : _a.addEventListener("change", this.run.bind(this)); } get restoreTime() { if (!this.input) return 1; const dur = window .getComputedStyle(this.input) .getPropertyValue("--dur"); const isMs = dur.indexOf("ms") > -1; const unit = isMs ? "ms" : "s"; let value = +dur.substring(0, dur.indexOf(unit)); if (!isMs) value *= 1e3; return value; } run() { if (this.input) { this.input.disabled = true; this.restoreTimeout = setTimeout( this.restore.bind(this), this.restoreTime ); } } restore() { if (this.input) { this.input.checked = false; this.input.disabled = false; } } } </script> </body> </html> |